﻿using B.S.DataBase.MyProject.Domain.Procurements;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Write.API.Applicantions.Command.ProcurementsCommand;

namespace T.E.ERP.Write.API.Applicantions.CommandHandler.ProcurementsCommandCommand
{
    /// <summary>
    /// 开票通知单的修改命令处理方法
    /// </summary>
    public class InvoiceSettlementEntityUdpCommandHandler:IRequestHandler<InvoiceSettlementEntityUdpCommand,APIResult<object>>
    {
        /// <summary>
        /// 开票通知单的仓储接口
        /// </summary>
        private readonly IBaseRepository<InvoiceSettlementEntity> iRepo;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="iRepo"></param>
        public InvoiceSettlementEntityUdpCommandHandler(IBaseRepository<InvoiceSettlementEntity>iRepo)
        {
            this.iRepo = iRepo;
        }

        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public  Task<APIResult<object>> Handle(InvoiceSettlementEntityUdpCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            var list =  iRepo.GetAll().Result.Where(x=>x.InvoiceSettlementEntityId==request.InvoiceSettlementEntityId).FirstOrDefault();
            list.InvoiceSettlementEntityId = request.InvoiceSettlementEntityId;
            list.Operator = request.Operator;
            list.Bank = request.Bank;
            list.CustomerName = request.CustomerName;
            list.DocumentStatus = request.DocumentStatus;
            var obj =  iRepo.Update(list).Result;
            if (obj > 0)
            {
                result.Code = APIEnum.修改成功;
                result.Msg = APIEnum.修改成功.ToString();
                result.data = obj;
            }
            else
            {
                result.Code = APIEnum.修改失败;
                result.Msg = APIEnum.修改失败.ToString();
            }
            return  Task.FromResult(result);




        }



    }
}
